Код:
//=============================================================================
// combining_items.js
//=============================================================================
/*:
* @author AppleDog
* @target MZ
* @plugindesc The plugin adds a menu for combining items in the inventory
* @help Now, when using an item from the inventory, you will be offered
* choosing what to do with it: Use - uses the item as usual
* Combin with - connects to other objects.
* In the plugin parameters, set combinations of items in the recipes field.
* In the "ingredients" enter the id of what you will combine, and in the
* "result" enter the id of the item that you will get.
* Back - just closes the window.
* @param action_name
* @desc Action name
* @type string[]
* @default ["Use","Combine with", "Back"]
*
* @param success_name
* @desc If successful, "success_name+ the name of the item!" will be shown
* @type string
* @default You made a
* @param fail_name
* @desc Текст при провале
* @type string
* @default It cannot be combined!
*
* @param item_recipe
* @desc recipe list
* @type struct<item>[]
* @default []
*/
/*:ru
* @author AppleDog
* @target MZ
* @plugindesc Плагин добавляет возможность соединять предметы в инвентаре.
* @help Теперь при использовании предмета из инвентаря будет предлагаться
* выбор, что с ним сделать: Использовать - использует предмет, как обычно
* Соеденить с - соединяет с других предметом.
* Выйти - просто закрывает в окно.
* В параметрах плагина в поле рецептов задайте комбинации предметов.
* В "ингредиенты" введите id того, что будете объединять, а в "результат"
* id предмета, который получится.
* @param action_name
* @desc Названия действий
* @type string[]
* @default ["Использовать","Соеденить c", "Выйти"]
*
* @param success_name
* @desc В случае успеха будет показано success_name+ название предмета!
* @type string
* @default Вы сделали
* @param fail_name
* @desc Текст при провале
* @type string
* @default Нельзя совместить!
*
* @param item_recipe
* @desc Список рецептов
* @type struct<item>[]
* @default []
*/
/*~struct~item:
* @param ingridient
* @desc id item to combine
* @type number[]
* @default []
* @param result
* @desc id result
* @type number
* @default 0
*/
var parameters = PluginManager.parameters('combining_items');
const item_recipe = []
for (let i = 0; i < JSON.parse(parameters["item_recipe"]).length; i++){
item_recipe.push(JSON.parse(JSON.parse(parameters["item_recipe"])[i]));
item_recipe[i].ingridient = JSON.parse(item_recipe[i].ingridient);
}
const ny_Scene_initialize = Scene_Item.prototype.initialize
Scene_Item.prototype.initialize = function() {
ny_Scene_initialize.call(this);
this.item_choosed;
STATE_USE = { USE: 0, COMBINING : 1, RESULT:2}
this.state_use = STATE_USE.USE;
};
const ny_Scene_ItemonItemCancel = Scene_Item.prototype.onItemCancel
Scene_Item.prototype.onItemCancel = function() {
ny_Scene_ItemonItemCancel.call(this)
this.item_choosed = null;
this.state_use = STATE_USE.USE;
}
const ny_Scene_ItemonItemOk = Scene_Item.prototype.onItemOk
Scene_Item.prototype.onItemOk = function() {
if(this.state_use == STATE_USE.USE){
this._window_item_action = new ny_window_item_action();
this._window_item_action.setHandler("ok", this.onActionOk.bind(this));
this.addWindow(this._window_item_action);
}
else{
if(this.item_choosed.id!=this.item().id){
var _is_item_create = false;
var _item_result_name = ""
for(let i = 0; i < item_recipe.length;i++){
var _recipe = item_recipe[i];
if(_recipe.ingridient.includes(String(this.item_choosed.id)) && _recipe.ingridient.includes(String(this.item().id))){
$gameParty.gainItem($dataItems[_recipe.result],1);
$gameParty.gainItem(this.item_choosed,-1);
$gameParty.gainItem(this.item(),-1);
SoundManager.playEquip();
_item_result_name = $dataItems[_recipe.result].name
_is_item_create = true
break;
}
}
if(_is_item_create == false){SoundManager.playBuzzer()}
this.item_choosed = null;
this.state_use = STATE_USE.RESULT
this.combining_complete_window = new CombiningComplete(_is_item_create,_item_result_name)
this.combining_complete_window.setHandler("ok", this.OkResult.bind(this));
this.addWindow(this.combining_complete_window)
}
else{
this.activateItemWindow()
SoundManager.playBuzzer();
}
}
}
Scene_Item.prototype.OkResult = function(){
this.combining_complete_window.deactivate();
this.combining_complete_window.destroy();
this.item_choosed = null;
this.state_use = STATE_USE.USE;
this._itemWindow.scrollTo(0, 0);
this.activateItemWindow();
}
Scene_Item.prototype.onActionCancel = function(){
this.item_choosed = null;
this.state_use = STATE_USE.USE;
this.activateItemWindow();
this._window_item_action.destroy();
}
Scene_Item.prototype.onActionOk = function(){
if(this._window_item_action.index() == 0){
ny_Scene_ItemonItemOk.call(this);
}
else if(this._window_item_action.index() == 1){
this.item_choosed = this.item()
this.state_use = STATE_USE.COMBINING
this.activateItemWindow()
}
else if(this._window_item_action.index() == 2){
this.activateItemWindow()
}
this._window_item_action.deactivate();
this._window_item_action.destroy();
}
///window item action
function ny_window_item_action() {
this.initialize.apply(this);
}
ny_window_item_action.prototype = Object.create(Window_Selectable.prototype);
ny_window_item_action.prototype.constructor = ny_window_item_action;
ny_window_item_action.prototype.initialize = function() {
this.action_type = JSON.parse(parameters['action_name'])//["Use","Combining","Back"]
const wx = Graphics.boxWidth/2-250;
const wy = Graphics.boxHeight/2-(this.itemLineRect(0).height*(this.action_type.length+1)+this.rowSpacing()*(this.action_type.length+1))/2;
const ww = 500;
const wh = this.itemLineRect(0).height*(this.action_type.length+1)+this.rowSpacing()*(this.action_type.length+1);
Window_Selectable.prototype.initialize.call(this, new Rectangle(wx, wy, ww, wh));
this.activate();
this.refresh();
}
ny_window_item_action.prototype.maxItems = function() {
return this.action_type.length;
};
ny_window_item_action.prototype.drawItem = function(index) {
const rect = this.itemLineRect(index);
this.drawItemName(this.action_type[index], rect.x, rect.y, rect.width);
}
ny_window_item_action.prototype.drawItemName = function(item, x, y, width){
this.drawText(item, x, y, width, "center");
}
///window item complete
function CombiningComplete() {
this.initialize.apply(this,arguments);
}
CombiningComplete.prototype = Object.create(Window_Selectable.prototype);
CombiningComplete.prototype.constructor = ny_window_item_action;
CombiningComplete.prototype.initialize = function(result, item_name) {
this.text_result = String(parameters["success_name"])+" "+ item_name+"!";
if(result == false){this.text_result = String(parameters["fail_name"])};
const wx = Graphics.boxWidth/2-300;
const wy = Graphics.boxHeight/2-62;
const ww = 600;
const wh = 125;
Window_Selectable.prototype.initialize.call(this, new Rectangle(wx, wy, ww, wh));
this.scrollTo(0, 0);
this.activate();
this.refresh();
}
CombiningComplete.prototype.maxItems = function() {
return 1;
};
CombiningComplete.prototype.drawItem = function(index) {
const rect = this.itemLineRect(index);
this.drawItemName("OK", rect.x, rect.y, rect.width);
this.changePaintOpacity(1);
}
CombiningComplete.prototype.itemRect = function(index) {
var rect = Window_Selectable.prototype.itemRect.call(this)
const maxCols = this.maxCols();
const itemWidth = this.itemWidth();
const itemHeight = this.itemHeight();
const colSpacing = this.colSpacing();
const rowSpacing = this.rowSpacing();
const col = index % maxCols;
const row = Math.floor(index / maxCols);
const x = col * itemWidth + colSpacing / 2 - this.scrollBaseX();
const y = 50+row * itemHeight* + rowSpacing / 2 - this.scrollBaseY();
const width = itemWidth - colSpacing;
const height = itemHeight - rowSpacing;
return new Rectangle(x, y, width, height);
}
CombiningComplete.prototype.drawItemName = function(item, x, y, width){
this.drawText(this.text_result, x, y-50, width, "center");
this.drawText(item, x, y, width, "center");
}
Социальные закладки